#ifndef MEMORYSTREAM_H
#define MEMORYSTREAM_H

#include "stream.h"

namespace Library
{

/**
 * A concrete class implementing an in-memory stream.
 */
class PLIBEXP MemoryStream : public Stream
{
	public:
						MemoryStream();
		virtual			~MemoryStream();

		virtual int32	read(void * buffer, int32 length);
		virtual int32	write(void * buffer, int32 length);
		virtual int32	seek(int32 offset, SeekFrom from);
		virtual int32	tell();

	protected:
		void			clean();

		void			decodeOffset(int32 offset, int32 * blockNumber,
							int32 * inodeNumber, int32 * pageNumber,
							int32 * pageOffset);

		uint8 *			retrievePage(int32 blockNumber, int32 inodeNumber,
							int32 pageNumber, bool8 create = false);

	private:
		// constants
		enum { BLOCKS = 64, INODES = 64, PAGES = 64, PAGE_SIZE = 8192 };

		// namespace
		struct	InodeTable;
		struct	BlockTable;

		// members
		int32			m_size;
		int32			m_offset;
		BlockTable *	m_superblock[ BLOCKS ];

	// prohibited
	private:
		MemoryStream(Stream &);
		MemoryStream & operator=(Stream &);
};

}; // namespace Library

#endif
